﻿using System;
using TheOutLetLibrary.Dominio;
using System.Data.OleDb;

namespace TheOutLetLibrary.Infraestrutura {

    public class Accessk_customerDAO : BaseDAO, IGenericDAO<k_customer> {

        public Accessk_customerDAO(OleDbTransaction transacao) 
            : base(transacao) {
        }

        public int Inclua(k_customer entity) {

            OleDbCommand comando = GetCommand();

            comando.CommandText =
                " INSERT INTO k_customer (" +
                " NR_PEDIDO, id, isPhysicalPerson, name, nickName, document, " +
                " gender, birthdate, email, comment) " +
                " VALUES (" +
                " @NR_PEDIDO, @id, @isPhysicalPerson, @name, @nickName, @document, " +
                " @gender, @birthdate, @email, @comment)";
            comando.Parameters.Add("@NR_PEDIDO", OleDbType.Integer).Value = entity.NR_PEDIDO;
            comando.Parameters.Add("@id", OleDbType.Integer).Value = entity.Id;
            comando.Parameters.Add("@isPhysicalPerson", OleDbType.VarChar).Value = entity.isPhysicalPerson.ToString();
            comando.Parameters.Add("@name", OleDbType.VarChar).Value = entity.name;
            comando.Parameters.Add("@nickName", OleDbType.VarChar).Value = entity.nickName;
            comando.Parameters.Add("@document", OleDbType.VarChar).Value = entity.document;
            comando.Parameters.Add("@gender", OleDbType.VarChar).Value = entity.gender;
            comando.Parameters.Add("@birthdate", OleDbType.VarChar).Value = entity.birthdate.ToString("s");
            comando.Parameters.Add("@email", OleDbType.VarChar).Value = entity.email;
            comando.Parameters.Add("@comment", OleDbType.VarChar).Value = entity.comment;
            comando.ExecuteNonQuery();

            comando.CommandText = "SELECT @@IDENTITY";
            entity.COD = Convert.ToInt32(comando.ExecuteScalar());
            return entity.COD;

        }

        public k_customer Ache(int Id) {
            throw new NotImplementedException();
        }
    }
}
